package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.model.YgProductRecommendModel;
import com.ygqh.baby.po.YgProductRecommend;
import com.ygqh.baby.service.YgProductRecommendService;
import com.ygqh.baby.utils.JsonUtils;

@Controller
@RequestMapping("/admin/recommend")
public class ProductRecommendController extends BaseController<Object, java.lang.Long>{
	
	@Autowired
	private YgProductRecommendService ygProductRecommendService;
	
	@RequestMapping("/getProductById")
	@ResponseBody
	public Map<String,Object> getProductById(Long groupId){
		List<YgProductRecommendModel> list =ygProductRecommendService.findProductByGroupId(null, groupId);
		ResultSet<YgProductRecommendModel> result=new ResultSet<YgProductRecommendModel>(1, list);
	    return result.toDatatables(null);
	}
	
	
	@RequestMapping("/getProductRecommendByGroupId")
	@ResponseBody
	public YgProductRecommend  getProductRecommendByGroupId(Long groupId){
		return ygProductRecommendService.findByGroupId(groupId);
	}	
	

	@RequestMapping("/saveProductRecommend")
	@ResponseBody
	public Message saveProductRecommend(String recommend){
		YgProductRecommend productRecommend = JsonUtils.toObject(recommend,YgProductRecommend.class);
		productRecommend.setCreateTime(new Date());
		productRecommend.setCreateBy(getSession().getTrueName());
		return ygProductRecommendService.save(productRecommend)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	}

	@RequestMapping("/updateProductRecommend")
	@ResponseBody
	public Message updateProductRecommend(String recommend){
		YgProductRecommend productRecommend = JsonUtils.toObject(recommend,YgProductRecommend.class);
		productRecommend.setUpdateTime(new Date());
		productRecommend.setUpdateBy(getSession().getTrueName());
		return ygProductRecommendService.update(productRecommend)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	}
	@RequestMapping("/deleteRecommend")
	@ResponseBody
	public Message deleteRecommend(Long id){		
		return ygProductRecommendService.deleteSoft(id)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	}
	
	
 	
}
